home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 71 / maccd 71.iso / macware / Cyclone 1.2 ƒ / Scripting / Convert files (advanced) < prev    next >
Encoding:
Text File  |  1999-11-06  |  2.7 KB  |  96 lines  |  [TEXT/ToyS]

  1. --Sample Cyclone script:
  2. --   1. converts files dragged on this script from Mac Roman to Unicode 16 bit, turnig off Cyclone alerts, but ordering error log,
  3. --   2. sets custom type and creator (BBEdit text),
  4. --   3.  moves output files to folder "Converted items" which should be created on desktop,
  5. --   4. renames output files by cutting a dot added by Cyclone.
  6.  
  7. --Create "Converted items" folder on desktop before running this script
  8. --Save this script as an application and drag some text files on it
  9. --Apple Script 1.3 is required for timed dialog boxes (remove "giving up after 20" if the script is not working for you)
  10.  
  11. property BBEditSignature : "R*ch"
  12. property textFileType : "TEXT"
  13.  
  14. on run
  15.     NoItemsSelected()
  16. end run
  17.  
  18. on open theList
  19.     ConvertFilesWithCyclone(theList)
  20. end open
  21.  
  22.  
  23. on ConvertFilesWithCyclone(theList)
  24.     
  25.     tell application "Cyclone"
  26.         activate
  27.         
  28.         set option NoAlertDoLog
  29.         
  30.         try
  31.             convert theList from Mac_Roman_Euro_Sign to Unicode_2_1_Standard
  32.         on error
  33.             display dialog "An error occured during conversion." buttons {"Stop"} default button 1 ¬
  34.                 giving up after 20
  35.         end try
  36.         set outList to result
  37.         
  38.         set option DoAlertNoLog
  39.         
  40.         quit
  41.     end tell
  42.     
  43.     tell application "Finder"
  44.         
  45.         --repeat with y in theList
  46.         --    delete y --move original to the trash
  47.         --end repeat
  48.         
  49.         repeat with curr_file in outList
  50.             --we must check if the output item exists
  51.             --Cyclone returns invalid file spec if conversion fails
  52.             if exists curr_file then
  53.                 --set the sample type and creator
  54.                 set creator type of curr_file to BBEditSignature
  55.                 set file type of curr_file to textFileType
  56.                 
  57.                 --move file to sample folder "Converted items" on the desktop
  58.                 set the moved_file to move curr_file to folder "Converted items" of desktop with replacing
  59.                 
  60.                 --cut the last char of filename which is a bullet
  61.                 set the current_name to name of moved_file
  62.                 set the new_name to (characters 1 thru -2 of the current_name) as string
  63.                 my rename_file(moved_file, the new_name)
  64.             end if
  65.         end repeat
  66.         
  67.         
  68.     end tell
  69.     
  70. end ConvertFilesWithCyclone
  71.  
  72. on NoItemsSelected()
  73.     display dialog "No file selected." & return & ¬
  74.         "Drag a text file onto this script." buttons {"OK"} default button 1 ¬
  75.         giving up after 20
  76. end NoItemsSelected
  77.  
  78. -- file renaming with replacing
  79. on rename_file(this_file, new_file_name)
  80.     tell application "Finder"
  81.         activate
  82.         
  83.         set the parent_container_path to (the container of this_file) as text
  84.         set the new_file to (the parent_container_path & new_file_name)
  85.         if (exists file new_file) then
  86.             delete file new_file
  87.         end if
  88.         
  89.         try
  90.             set the name of this_file to new_file_name
  91.         on error
  92.             display dialog "Error renaming file" buttons {"OK"} default button 1 ¬
  93.                 giving up after 20
  94.         end try
  95.     end tell
  96. end rename_file